package com.bjqg.bjqg01.bjqg.fragment;/**
 * Created by dell on 2017/4/5/0005.
 */

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.LoginActivity;
import com.bjqg.bjqg01.bjqg.activity.address.activity.AddressManagerActivity;
import com.bjqg.bjqg01.bjqg.dialog.LogOutDialog;
import com.yzq.zxinglibrary.android.FinishListener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


/**
 * created by LiChengalin at 2017/4/5/0005
 */
public class FouthFragment extends BaseFragment {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_top_title)
    TextView tvTopTitle;
    @BindView(R.id.select)
    ImageView select;
    @BindView(R.id.iv)
    ImageView iv;
    @BindView(R.id.version_code_fragment)
    TextView versionCodeFragment;
    @BindView(R.id.test_update_fragment)
    RelativeLayout testUpdateFragment;
    @BindView(R.id.iv_go_address)
    ImageView ivGoAddress;
    @BindView(R.id.text_address)
    RelativeLayout textAddress;
    @BindView(R.id.test_quit)
    TextView testQuit;

    Unbinder unbinder;
    private View view;
    LogOutDialog.Builde dialog;

    public static FouthFragment newInstance() {
        Bundle bundle = new Bundle();
        FouthFragment fragment = new FouthFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_me, container, false);
        unbinder = ButterKnife.bind(this, view);
        initdate();
        showQuitDialog();
        return view;
    }


    private void initdate() {
        back.setVisibility(View.INVISIBLE);
        tvTopTitle.setText("个人中心");
        select.setVisibility(View.INVISIBLE);
        versionCodeFragment.setText("已是最新版本");
    }

    @OnClick({R.id.test_quit, R.id.text_address, R.id.test_update_fragment})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.test_quit:
                dialog.create().show();
                break;
            case R.id.text_address:
                Intent intent7 = new Intent(getActivity(), AddressManagerActivity.class);
                intent7.putExtra("finish", "no");
                startActivity(intent7);
                break;
            case R.id.test_update_fragment:
                Toast.makeText(getActivity(), "当前版本已经是最新版本", Toast.LENGTH_SHORT).show();
                break;
        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    private void showQuitDialog() {

        dialog = new LogOutDialog.Builde(getActivity());
        dialog.setCloseListener(new DialogInterface.OnClickListener() {//确定
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Intent tologin = new Intent(getActivity(), LoginActivity.class);
                startActivity(tologin);
                getActivity().finish();
            }
        });
        dialog.setConfireListener(new DialogInterface.OnClickListener() {//取消
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }
}
